<?php echo view('header.html');?>

<body class="layui-view-bodys">
    <div class="layui-content">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-body">

                    <table class="layui-table" lay-size="sm">
                        <colgroup>
                            <col width="150">
                            <col width="200">
                            <col>
                        </colgroup>
                        <thead>
                            <tr>
                                <th>应用名称</th>
                                <th>应用目录</th>
                                <th>应用版本</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if($list):?>
                            <?php foreach($list as $k=>$v):?>
                            <tr>
                                <td><?=$v['name']?></td>
                                <td><?=$v['dirname']?></td>
                                <td>Version: <?=$v['version']?></td>
                                <td><a class="layui-btn layui-btn-normal layui-btn-xs installmodule" data-dirname="<?=$v['dirname']?>">安装应用</a></td>
                            </tr>
                            <?php endforeach;?>
                            <?php endif;?>
                        </tbody>
                    </table>

                </div>
            </div>
        </div>
    </div>
    <?php echo view('footer.html');?>
    <script type="text/javascript">
        layui.use(['form', 'jquery', 'layer', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;

            
            /**index**/

            $("body").on('click', '.installmodule', function () {
                var dirname = $(this).attr('data-dirname');
                layer.confirm('确定安装吗？', { icon: 3, title: '提示' }, function (index) {
                    $.post(adminpath + 'admin/module/install', { dirname: dirname }, function (res) {
                        if (res.code == 0) {
                            layer.msg(res.msg, {
                                icon: 1,
                                time: 1000
                            }, function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                // parent.location.href = adminpath + '/role/index';
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, {
                                icon: 5,
                                time: 1500,
                                anim: 6
                            });
                        }
                    }, 'json');
                    layer.close(index);
                });
            });

        })
    </script>
</body>

</html>
